import { randomString } from '@/views/aplid/FormDesign/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '表名称',
			prop: 'templateName',
			type: 'input',
			rules: [{ required: true, message: '请输入表名称' }],
			span: 24,
		},
		{
			label: '介 绍',
			prop: 'info',
			type: 'textarea',
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '模板编号',
			prop: 'templateNo',
			type: 'input',
			span: 6,
		},
		{
			label: '模板名称',
			prop: 'templateName',
			type: 'input',
			span: 6,
		},
		{
			label: '模板介绍',
			prop: 'info',
			type: 'input',
			span: 6,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '表格编号', prop: 'templateNo' },
		{ label: '标题', prop: 'templateName' },
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_tableTemplate_page',
	add: 'view_tableTemplate_add',
	edit: 'view_tableTemplate_edit',
	delete: 'view_tableTemplate_del',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '隐患评估表',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'templateName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	paramsObj: {
		type: 6,
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '设计',
			type: 'primary',
			operate: 'design',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			if (!form.templateNo) {
				form.templateNo = randomString(10)
			}
			resolve(form)
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			resolve(query)
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(arr)
		})
	},
	dialogConfig: {
		width: '85%',
	},
	searchConfig,
	formConfig,
	tableConfig,
}
